/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ssi.mrms.dao.mapping;

import com.ssi.mrms.model.RMrmlstModel;
import com.ssi.mrms.model.RMwnltModel;
import com.ssi.mrms.model.TowerModel;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.RowMapper;

/**
 *
 * @author jirapatjantsakool
 */
public class WarningLetterMapping implements RowMapper<RMwnltModel>  {
    
    public RMwnltModel mapRow(ResultSet rs, int line) throws SQLException {
        ResultSetExtractor<RMwnltModel> extractor = new ResultSetExtractor<RMwnltModel>() {
            public RMwnltModel extractData(ResultSet rs) throws SQLException, DataAccessException {
                RMwnltModel model = new RMwnltModel();
                model.setWnltid(rs.getInt("WNLTID"));
                model.setWnltdocno(rs.getString("WNLTDOCNO"));
                model.setWnltstat(rs.getString("WNLTSTAT"));
                model.setWnltattn(rs.getString("WNLTATTN"));
                model.setWnltdat(rs.getDate("WNLTDAT"));
                model.setWnltsbj(rs.getString("WNLTSBJ"));
                model.setWnltdtl(rs.getString("WNLTDTL"));
                model.setWnltfilepath(rs.getString("WNLTFILEPATH"));
                model.setWnltcreby(rs.getString("WNLTCREBY"));
                model.setWnltcredat(rs.getDate("WNLTCREDAT"));
                model.setWnltupdby(rs.getString("WNLTUPDBY"));
                model.setWnltupddat(rs.getDate("WNLTUPDDAT"));
                model.setRlrmid(rs.getInt("RLRMID"));
                
                /* ---- Tower Data From Join Table------*/
                TowerModel tower = new TowerModel();
                tower.setTower(rs.getString("RLSTTOWER"));
                tower.setFloor(rs.getString("RLSTFLOOR"));
                tower.setUnitNo(rs.getString("RLSTUNITNO"));
                tower.setAddress(rs.getString("RLSTADDR"));
                model.setTower(tower);

                return model;
            }
        };
        return extractor.extractData(rs);
    }
}
